﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QuanLyShopThoiTrang.QuanLyShopThoiTrang_BUS_WS;

namespace QuanLyShopThoiTrang
{
    public partial class ManHinhChinh : Form
    {
        LoaiNhanVien lnv = new LoaiNhanVien();
        QLSTT_BUSSoapClient ws = new QLSTT_BUSSoapClient();
        bool thoat = true;
        private Form1 f = new Form1();
        NhanVien nv = new NhanVien();

        public ManHinhChinh()
        {
            InitializeComponent();
        }

        public void Set(NhanVien n)
        {
            nv = ws.NhanVien_LayNVBangTenDangNhap(n);
            textBox1.Text = nv.NhanVien_TenDayDu;
            lnv = ws.NhanVien_LayLoaiNV(nv);
            textBox2.Text = lnv.LoaiNhanVien_Ten;

            if (lnv.LoaiNhanVien_Ten == "Chủ cửa hàng")
                return;
            if (lnv.LoaiNhanVien_Ten == "Nhân viên bán hàng")
            {
                quanLySanPhamToolStripMenuItem.Visible = false;
                quanLyNhanVienToolStripMenuItem1.Visible = false;
                quanLyNhaCungCapToolStripMenuItem1.Visible = false;
                quanLyHoaDonBanHangToolStripMenuItem1.Visible = false;
                button5.Enabled = false;
                button5.BackColor = Color.Gray;
                button6.Enabled = false;
                button6.BackColor = Color.Gray;
                button7.Enabled = false;
                button7.BackColor = Color.Gray;
                button8.Enabled = false;
                button8.BackColor = Color.Gray;
                return;
            }
            if(lnv.LoaiNhanVien_Ten == "Nhân viên quản lý")
            {
                quanLyNhanVienToolStripMenuItem1.Visible = false;
                quanLyNhaCungCapToolStripMenuItem1.Visible = false;
                quanLyBanHangToolStripMenuItem.Visible = false;
                button4.Enabled = false;
                button4.BackColor = Color.Gray;
                button7.Enabled = false;
                button7.BackColor = Color.Gray;
                //button9.Enabled = false;
                //button9.BackColor = Color.Gray;

                return;
            }
            if(lnv.LoaiNhanVien_Ten == "Nhân viên quản trị")
            {
                quanLyBanHangToolStripMenuItem.Visible = false;
                quanLySanPhamToolStripMenuItem.Visible = false;
                quanLyHoaDonBanHangToolStripMenuItem1.Visible = false;
                button4.Enabled = false;
                button4.BackColor = Color.Gray;
                button5.Enabled = false;
                button5.BackColor = Color.Gray;
                button6.Enabled = false;
                button6.BackColor = Color.Gray;
                button8.Enabled = false;
                button8.BackColor = Color.Gray;
                return;
            }
        }

        private void thoatToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        public void SetForm(Form1 form)
        {
            f = form;
        }

        private void ManHinhChinh_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (thoat)
                f.Close();
            f.Visible = true;
        }

        private void thongTinChuongTrinhToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ThongTinChuongTrinh ttct = new ThongTinChuongTrinh();
            ttct.Show();
        }

        private void dangXuatToolStripMenuItem_Click(object sender, EventArgs e)
        {
            thoat = false;
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            thoat = false;
            this.Close();
        }

        private void nhapHangMoiToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            NhapHang nh = new NhapHang();
            nh.Show();
        }

        private void lapPhieuBanHangToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            LapPhieuBanHang lpbh = new LapPhieuBanHang();
            lpbh.Set(nv);
            lpbh.Show();
        }

        private void danhSachHangToolStripMenuItem_Click(object sender, EventArgs e)
        {
            QuanLyHangHoa qlhh = new QuanLyHangHoa();
            qlhh.Show();
        }

        private void quanLyNhaCungCapToolStripMenuItem_Click(object sender, EventArgs e)
        {
            QuanLyNhaCungCap qlncc = new QuanLyNhaCungCap();
            qlncc.Show();
        }

        private void quanLyNhanVienToolStripMenuItem_Click(object sender, EventArgs e)
        {
            QuanLyNhanVien qlnv = new QuanLyNhanVien();
            qlnv.Show();
        }

        private void quanLyHoaDonMuaHangToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void ketNoiDuLieuToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ws.LoaiSanPham_LayDanhSach();
            MessageBox.Show("Kết nối thành công.");
        }

        private void button3_Click(object sender, EventArgs e)
        {
            button3.Text = "Đang kết nối...";
            ws.LoaiSanPham_LayDanhSach();
            MessageBox.Show("Kết nối thành công.");
            button3.Text = "Đã kết nối";
            button3.Image = Properties.Resources.button_3b2;
        }

        private void quanLyHoaDonBanHangToolStripMenuItem_Click(object sender, EventArgs e)
        {
            QuanLyHoaDonBanHang qlhdbh = new QuanLyHoaDonBanHang();
            qlhdbh.Show();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            DoiMatKhau dmk = new DoiMatKhau();
            dmk.Set(this, nv);
            dmk.ShowDialog();
        }

        public void Change(NhanVien n)
        {
            nv = new NhanVien();
            nv = n;
        }

        private void nhapHangMoiToolStripMenuItem2_Click(object sender, EventArgs e)
        {
            NhapHang nh = new NhapHang();
            nh.Show();
        }

        private void lapPhieuBanHangToolStripMenuItem2_Click(object sender, EventArgs e)
        {
            LapPhieuBanHang lpbh = new LapPhieuBanHang();
            lpbh.Set(nv);
            lpbh.Show();
        }

        private void quanLySanPhamToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            QuanLyHangHoa qlhh = new QuanLyHangHoa();
            qlhh.Show();
        }

        private void quanLyNhaCungCapToolStripMenuItem2_Click(object sender, EventArgs e)
        {
            QuanLyNhaCungCap qlncc = new QuanLyNhaCungCap();
            qlncc.Show();
        }

        private void themNhanVienToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ThemNhanVien tnv = new ThemNhanVien();
            tnv.Show();
        }

        private void quanLyHoaDonBanHangToolStripMenuItem2_Click(object sender, EventArgs e)
        {
            QuanLyHoaDonBanHang qlhd = new QuanLyHoaDonBanHang();
            qlhd.Show();
        }

        private void quanLyNhanVienToolStripMenuItem2_Click(object sender, EventArgs e)
        {
            QuanLyNhanVien qlnv = new QuanLyNhanVien();
            qlnv.Show();
        }

        private void button9_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            if (lnv.LoaiNhanVien_Ten == "Chủ cửa hàng" || lnv.LoaiNhanVien_Ten == "Nhân viên bán hàng")
            {
                LapPhieuBanHang lpbh = new LapPhieuBanHang();
                lpbh.Set(nv);
                lpbh.Show();
            }
        }

        private void button5_Click(object sender, EventArgs e)
        {
            if (lnv.LoaiNhanVien_Ten == "Chủ cửa hàng" || lnv.LoaiNhanVien_Ten == "Nhân viên quản lý")
            {
                NhapHang nh = new NhapHang();
                nh.Show();
            }
        }

        private void button6_Click(object sender, EventArgs e)
        {
            if (lnv.LoaiNhanVien_Ten == "Chủ cửa hàng" || lnv.LoaiNhanVien_Ten == "Nhân viên quản lý")
            {
                QuanLyHangHoa qlhh = new QuanLyHangHoa();
                qlhh.Show();
            }
        }

        private void button7_Click(object sender, EventArgs e)
        {
            if (lnv.LoaiNhanVien_Ten == "Chủ cửa hàng" || lnv.LoaiNhanVien_Ten == "Nhân viên quản trị")
            {
                QuanLyNhanVien qlnv = new QuanLyNhanVien();
                qlnv.Show();
            }
        }

        private void button8_Click(object sender, EventArgs e)
        {
            if (lnv.LoaiNhanVien_Ten == "Chủ cửa hàng" || lnv.LoaiNhanVien_Ten == "Nhân viên quản lý")
            {
                QuanLyHoaDonBanHang ql = new QuanLyHoaDonBanHang();
                ql.Show();
            }
        }
    }
}
